using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
using CodePlex.Resourceful.Json;

namespace CodePlex.Resourceful
{

    public class ClientResponse
    {
        private readonly HttpStatus _status;
        private readonly NameValuePairs _headers;
        private readonly Stream _stream;

        public ClientResponse(HttpStatus status, NameValuePairs headers, Stream stream)
        {
            _status = status;
            _headers = headers;
            _stream = stream;

        }

        public NameValuePairs Headers
        {
            get
            {
                return _headers;
            }
        }
        public HttpStatus HttpStatus
        {
            get
            {
                return _status;
            }
        }




        public Stream AsStream()
        {
            if (_stream.CanSeek)
            {
                _stream.Position = 0;
            }
            return _stream;
        }

        public TextReader AsTextReader()
        {
            return new StreamReader(this.AsStream());
        }

        public string AsString()
        {
            return this.AsTextReader().ReadToEnd();
        }

        public XmlReader AsXmlReader()
        {
            return XmlReader.Create(this.AsTextReader());
        }

        public JsonReader AsJsonReader()
        {
            return new JsonReader(this.AsTextReader());
        }

#if SILVERLIGHT
#else
        public XmlDocument AsXmlDocument()
        {
            XmlDocument rt = new XmlDocument();
            rt.Load(this.AsTextReader());
            return rt;
        }
#endif

    }

}
